package org.celery.modules.user.wrapper;

import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.celery.modules.user.entity.UserDomain;
import org.celery.modules.user.vo.UserDomainVO;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;

import javax.swing.*;

/**
 * 用户与域名关联表包装类,返回视图层所需的字段
 *
 * @author Celery
 * @since 2022-04-06
 */
public class UserDomainWrapper extends BaseEntityWrapper<UserDomain, UserDomainVO>  {

    public static UserDomainWrapper build() {
        return new UserDomainWrapper();
    }

	@Override
	public UserDomainVO entityVO(UserDomain userDomain) {
		UserDomainVO userDomainVO = BeanUtil.copy(userDomain, UserDomainVO.class);
		IUserService userService = SpringUtil.getBean(IUserService.class);
		User user = userService.getById(userDomain.getUserId());
		if (Func.isNotEmpty(user)) {
			userDomainVO.setUserName(user.getName());
		}

		return userDomainVO;
	}

}
